package xml.uidElements.output;

import java.util.ArrayList;

import xml.others.UIDException;
import xml.uidElements.TransitionFromSet;

public class OutputDataItemSet extends AbstractOutputDataItem {

	private OutputDataItem dataItem;
	private int cardinalityMin;
	private int cardinalityMax;
	private boolean optional = false;
	private ArrayList<TransitionFromSet> listOutgoingTransitions;

	public OutputDataItemSet(String name) {

		this.dataItem = new OutputDataItem(name);
	}

	public OutputDataItemSet(String name, String domain) {
		this.dataItem = new OutputDataItem(name, domain);
	}

	public void setCardinality(int cardinalityMin, int cardinalityMax) {

		this.setCardinalityMin(cardinalityMin);
		this.setCardinalityMax(cardinalityMax);
	}

	private void setCardinalityMin(int cardinalityMin) {
		this.cardinalityMin = cardinalityMin;
	}

	public int getCardinalityMin() {
		return cardinalityMin;
	}

	private void setCardinalityMax(int cardinalityMax) {
		this.cardinalityMax = cardinalityMax;
	}

	public int getCardinalityMax() {
		return cardinalityMax;
	}

	@Override
	public String getName() {
		return dataItem.getName();
	}

	public String getDomain() {
		return dataItem.getDomain();
	}

	public void setDomain(String domain) {
		this.dataItem.setDomain(domain);
	}

	public void setOptional(boolean optional) {
		dataItem.setOptional(optional);
		this.optional = optional;
	}

	public boolean isOptional() {
		return optional;
	}

	public void insertOutgoingTransition(TransitionFromSet transition) {

		if (listOutgoingTransitions == null)
			listOutgoingTransitions = new ArrayList<TransitionFromSet>();

		for (int i = 0; i < this.listOutgoingTransitions.size(); i++) {
			TransitionFromSet trans = this.listOutgoingTransitions.get(i);
			if (trans.getId().equals(transition.getId()))
				throw new UIDException(UIDException.EXISTING_TRANSITION,
						"There is already a transition with this id");
		}
		listOutgoingTransitions.add(transition);

	}

}
